import http.cookiejar
import urllib.request


def get_cookie(url):
    cookie_jar = http.cookiejar.CookieJar()
    cookie_processor = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cookie_jar))
    cookie_processor.open(url)
    return cookie_jar;


def get_scalers_forum_cookie():
    cookie_str = "pt_local_token=2-; pac_uid=1_405164955; tvfe_boss_uuid=0dfefca8ba89426b; \
sd_userid=87871481518368883; sd_cookie_crttime=1481518368883; \
verifysession=h0106732036a94ab0dbd8f4a74656a03a66ba1aa1f6d3c753d64dfcd4df096460746fa1cacc6a71889d40934a626656c333; \
ptui_loginuin=405164955; uniqueuid=274e54b6a2180d071f2c08b8221f4ca0; o_cookie=89044094; pgv_info=ssid=s3052249034; \
pgv_pvid=4483946255; ptcz=fcdfb60c288d118217be0a7b471ae4346331b7274cb0af7369cf77c03475f0cb; pt2gguin=o0089044094; \
uin=o0089044094; skey=MO8uhgd4EJ; ptisp=ctc; MANYOU_SESSIONID_bf895=4a6f2245becb9ec2fe11375a1e669d28; \
qqUser=%7B%22uin%22%3A89044094%2C%22nickName%22%3A%22%20Stef%20Moon%22%7D; security_cookiereport=1489230184"

    cookie_arr = cookie_str.split("; ")
    cookie_jar = http.cookiejar.CookieJar()
    for cookie_ele in cookie_arr:
        cookie_ele_arr = cookie_ele.split("=")
        cookie_item = http.cookiejar.Cookie(version=0, name=cookie_ele_arr[0], value=cookie_ele_arr[1], port=None, port_specified=False,
                                            domain='qgc.qq.com',
                                            domain_specified=False, domain_initial_dot=False, path='/314962432',
                                            path_specified=True, secure=False,
                                            expires=None, discard=True, comment=None, comment_url=None,
                                            rest={'HttpOnly': None}, rfc2109=False)
        cookie_jar.set_cookie(cookie_item)

    return cookie_jar
